#ifndef __CACHEMANAGER_H__
#define __CACHEMANAGER_H__

#include "LRUCache.h"
#include <vector>

using std::vector;

class LRUcache;

class CacheManager
{
public:
    static CacheManager *getInstance();
    void initCache(const string &filename); //从磁盘文件中读取缓存信息
    LRUCache &getCache(size_t idx); //获取某个缓存
    void periodicUpdateCaches(); //定时更新所有缓存

    //嵌套类，控制CacheManager的释放
    class AutoRelease
    {
    public:
        AutoRelease(){

        } 
        ~AutoRelease(){
            if(CacheManager::_pInstance){
                delete CacheManager::_pInstance;
                _pInstance = nullptr;
            }
        }
    };
private:
    CacheManager() = default;
    ~CacheManager() = default;
    static CacheManager *_pInstance;
private:
    vector<LRUCache> _cacheList; // 缓存的数量与线程个数一致
    static AutoRelease _ar;
};

#endif